/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package domain;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import domain.Game.action;
import domain.exceptions.CannotMoveThereException;

/**
 *
 * @author shaigi
 */
public class AgentHuman extends Agent {
    public AgentHuman(String name,action lastDirection, String assignment) {
        super(name, lastDirection, assignment);
    }
//    public AgentHuman(String name,action lastDirection, int arsenal, String assignment) {
//        super(name, lastDirection, arsenal, assignment);
//    }    
    public AgentHuman(AgentHuman other) {
    	super(other);
	}

    @Override
    public void play(Board board, Vector<Agent> agents, int maxSteps) {
        //direction lastDirection = getLastDirection();
        //Square nextSquare = null;
        //nextSquare = getSquareFromUser();

    	if (!isDead()){
	    	action act = getDirectionFromHuman();
	        if (act != null){
	            try {
	                act(act, board, agents);
	            } catch (CannotMoveThereException ex) {
	                Debug.println(getName()+ " says: \"Can't move there\"");
	            }
	        }
    	}
    	else{
    		System.out.println("I'm dead");
    		try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
    	}
    }


    public char readChar(){
		BufferedReader userRead = new BufferedReader(new InputStreamReader(System.in));
		try {
			String lineIn = userRead.readLine();
			return lineIn.charAt(0);
		} catch (IOException e) {
			System.err.println("There might be a problem with the input...exiting the program");
			e.printStackTrace();
		//	throw new IOException();
		}
		return '-';
	}
    
    
    
    
    private action getDirectionFromHuman() {
    	action act = null;
    	 
    	char c = '0';
    	System.out.print("Put direction: ");
    	c = readChar();		
		switch (c){
			case 'r': act = action.RIGHT;	break;
			case 'd': act = action.DOWN;	break;
			case 'l': act = action.LEFT;	break;
			case 'u': act = action.UP;		break;
			case 's': act = action.SHOOT;	break;
		}
		
    	return act;
	}

/*	private boolean checkLocation(int location) {
        throw new UnsupportedOperationException("Not yet implemented");
    }*/

/*    //TODO: complete this method
    private Square getSquareFromUser() {
        Scanner reader = new Scanner(System.in);
        boolean validLocation=false;
        while(validLocation==false){
            Debug.println("Please enter the number of square you would like to move to");
            int location=reader.nextInt();
            validLocation=checkLocation(location);
            if(!validLocation){
                Debug.println("not a valid location!");
            }
            else{

            }
        }
        throw new UnsupportedOperationException("Not yet implemented");
    }*/
/*
    private boolean isIcy(int location) {
        throw new UnsupportedOperationException("Not yet implemented");
    }*/
}
